ccR.Death_Knight.Talent = {
	-- Tier 1
		-- Plaguebearer
		Plague_Leech = 
		function()
			local vRunesDepleted = 0
			for i= 1, 6 do 
				local start, duration, runeReady = GetRuneCooldown(i)
				if not runeReady and start > 0 and start < GetTime()-(duration/2) then vRunesDepleted = vRunesDepleted + 1 end
				--if not runeReady then vRunesDepleted = vRunesDepleted + 1 end
			end 
			if ccR.Spell.Is.Ready(PLAGUE_LEECH)	 
			and vRunesDepleted >= 2
			then
				for x = 1, #ccR_Enemies_Within_44 do 
					local vUnit = ccR_Enemies_Within_44[x] 
					if (
							(not ccR.Unit.Is.Boss(vUnit) and (ccR.Unit.Has.MyDebuff(vUnit, FROST_FEVER) and ccR.Unit.Has.MyDebuff(vUnit, BLOOD_PLAGUE)) or ccR.Unit.Has.MyDebuff(vUnit, NECROTIC_PLAGUE_DEBUFF))
							or
							(ccR.Unit.Is.Boss(vUnit) and (ccR.Unit.Has.MyDebuff(vUnit, FROST_FEVER) and ccR.Unit.MyDebuffDuration(vUnit, BLOOD_PLAGUE, "<=", 3)) or ccR.Unit.MyDebuffDuration(vUnit, NECROTIC_PLAGUE_DEBUFF, "<=", 3))
						)
					and ccR.Spell.CanAttack(PLAGUE_LEECH, vUnit) 
					and ccR.Player.Is.Facing(vUnit)
					then 
						ccR.Cast.Attack(PLAGUE_LEECH, vUnit)
					end
				end
			end
		end,
		Unholy_Blight =	function(count) if count == nil then count = 4 end if ccR.Spell.Is.Ready(UNHOLY_BLIGHT) and ccR.Player.Has.Talent(UNHOLY_BLIGHT) and ccR.Player.Count(10) >= count then ccR.Cast.Spell(UNHOLY_BLIGHT) end end,
	-- Tier 2
		Lichborne = function() if ccR.Spell.Is.Ready(LICHBORNE) then local eventIndex = C_LossOfControl.GetNumEvents() while (eventIndex > 0) do local _, _, text = C_LossOfControl.GetEventInfo(eventIndex) if text == LOSS_OF_CONTROL_DISPLAY_CHARM or text == LOSS_OF_CONTROL_DISPLAY_FEAR or text == LOSS_OF_CONTROL_DISPLAY_SLEEP then ccR.Cast.Spell(LICHBORNE)	return end eventIndex = eventIndex - 1 end end end,
		Anti_Magic_Zone = function() end,
		-- Purgatory
	-- Tier 3
		Deaths_Advance = function() if ccR.Spell.Is.Ready(DEATHS_ADVANCE) and ccR.Player.Is.Moving() and ccR.Var("Player_Moving_Duration") >= ccR.Var("Deaths_Advance_Time") and ccR.Player.Has.Talent(DEATHS_ADVANCE) and HasFullControl() and not UnitOnTaxi("Player") and not IsMounted() and not ccR.Player.IsDead() and not UnitUsingVehicle("Player") and not IsUsingVehicleControls() and not ccR.Player.Has.Buff(136461) then ccR.Cast.Spell(DEATHS_ADVANCE) end end,
		-- Chilblains
		Asphyxiate = function() end,
	-- Tier 4
		Blood_Tap =	function(charges) if charges == nil then charges = 5 end if ccR.Spell.Is.Ready(BLOOD_TAP) and ccR.Player.Has.Talent(BLOOD_TAP) and (ccR.Player.Has.Buff(BLOOD_CHARGE) and ccR.Player.BuffStacks(BLOOD_CHARGE) >= charges) then if (not select(3, GetRuneCooldown(1)) and not select(3, GetRuneCooldown(2))) or (not select(3, GetRuneCooldown(3)) and not select(3, GetRuneCooldown(4))) or (not select(3, GetRuneCooldown(5)) and not select(3, GetRuneCooldown(6))) then ccR.Cast.Spell(BLOOD_TAP) end end end,
		-- Runic Empowerment
		-- Runic Corruption
	-- Tier 5
		Death_Pact = function(health) if health == nil then health = 50 end if ccR.Spell.Is.Ready(DEATH_PACT) and ccR.Player.Has.Talent(DEATH_PACT) and ccR.Player.Health() <= health then ccR.Cast.Spell(DEATH_PACT) end end,
		Death_Siphon = function(health) if health == nil then health = 50 end if ccR.Spell.Is.Ready(DEATH_SIPHON) and ccR.Player.Has.Talent(DEATH_SIPHON)	and ccR.Player.Health() <= health then local vFoundDeathRune = false for x = 1, 6 do local _, _, runeReady = GetRuneCooldown(x) if GetRuneType(x) == 4 and runeReady == true then vFoundDeathRune = true end end if vFoundDeathRune and ccR.Spell.CanAttack(DEATH_SIPHON) then ccR.Cast.Attack(DEATH_SIPHON) end end end,
		Conversion = function(health) if health == nil then health = 50 end if ccR.Spell.Is.Ready(CONVERSION) and ccR.Player.Has.Talent(CONVERSION) and ccR.Player.Health() <= health and ccR.Player.Runic_Power() >= 30 and not ccR.Player.Has.Buff(CONVERSION) then ccR.Cast.Spell(CONVERSION) end	end,
	-- Tier 6
		Gorefiends_Grasp = function(count) if count == nil then count = 4 end if ccR.Spell.Is.Ready(GOREFIENDS_GRASP) and ccR.Player.Has.Talent(GOREFIENDS_GRASP) and ccR.Player.Count(20) >= count then ccR.Cast.Spell(GOREFIENDS_GRASP) end end,
		Remorseless_Winter = function(count) if count == nil then count = 4 end if ccR.Spell.Is.Ready(REMORSELESS_WINTER) and ccR.Player.Has.Talent(REMORSELESS_WINTER) and ccR.Player.Count(8) >= count then ccR.Cast.Spell(REMORSELESS_WINTER) end end,
		Desecrated_Ground = function() if ccR.Spell.Is.Ready(DESECRATED_GROUND) then local eventIndex = C_LossOfControl.GetNumEvents() while (eventIndex > 0) do local _, _, text = C_LossOfControl.GetEventInfo(eventIndex) if text == LOSS_OF_CONTROL_DISPLAY_ROOT or text == LOSS_OF_CONTROL_DISPLAY_SNARE or text == LOSS_OF_CONTROL_DISPLAY_STUN_MECHANIC or text == LOSS_OF_CONTROL_DISPLAY_STUN or text == LOSS_OF_CONTROL_DISPLAY_FEAR or text == LOSS_OF_CONTROL_DISPLAY_HORROR then ccR.Cast.Spell(DESECRATED_GROUND) return end eventIndex = eventIndex - 1 end end end,
	-- Tier 7
		-- Neocrotic plague
		-- Defile 
		Breath_of_Sindragosa = 
		function(count)
			if count == nil then count = 4 end
			if ccR.Spell.Is.Ready(BREATH_OF_SINDRAGOSA) then
				local vCount = 0
				for x = 1, # ccR_Enemies_Within_12 do
					local vUnit = ccR_Enemies_Within_12[x]
					if ccR.Unit.Exists(vUnit)
					and ccR.Unit.Angle(vUnit) <= 90
					then
						vCount = vCount + 1
					end
				end
				if vCount >= count then ccR.Cast.Spell(BREATH_OF_SINDRAGOSA) end
			end
		end,
}
setmetatable(ccR.Death_Knight.Talent, ccR.Death_Knight)